package datos.clases;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;
import tipos.clases.Catastrofe;
import datos.interfaces.ICatastrofeDAO;

public class JDBCCatastrofeDAO implements ICatastrofeDAO{

	public JDBCCatastrofeDAO(){}
	
public List select() {
		
		Connection c = ConnectionManager.getInstance().checkOut();
		List res = new LinkedList();
		PreparedStatement stmt = null;
        ResultSet result = null;        
        String sql = "SELECT * FROM Catastrofe";
        
        try{
        	if(c==null){
        		System.out.println("No hay conexion");
        	}
        	stmt = c.prepareStatement(sql);      
        	stmt.executeQuery(sql);
            result = stmt.executeQuery();    
            while (result.next()) {
                Catastrofe temp = new Catastrofe();               
                temp.setID(result.getInt("Id"));
                temp.setLugar(result.getString("Lugar"));     
                temp.setDescripcion(result.getString("Descripcion"));    
                temp.setProyecto(result.getString("Proyecto"));    
                temp.setFecha(result.getDate("Fecha"));
                res.add(temp);
            }
            
        }catch(SQLException e){
        	System.out.println("Error");
        }finally{
        	  try {
                  if (result != null) {
                      result.close();
                  }
                  if (stmt != null) {
                      stmt.close();
                  }
              } catch (SQLException e) {
              }
        }
		return res;
	}

}

